
<!-- 平台商协议管理地址：http://localhost:9527/operation/agreement -->
<!-- /pages/agreement/index?type=协议类型标识&title=页面标题 -->
<template>
	<view class="agreementWarp">
		<view>
			<view class="text cancelTxt">
				<jyf-parser :html="dataHtml" 
					ref="article" :tag-style="tagStyle"></jyf-parser>
			</view>
		</view>
	</view>
</template>
<script>
	import {
		getAgreementDetailApi
	 } from "@/api/agreement.js"
	import jyfParser from "@/components/jyf-parser/jyf-parser";
	export default {
		components: {
			"jyf-parser": jyfParser
		},
		watch: {
			pageTitle: {
				handler(newValue, oldValue) {
					uni.setNavigationBarTitle({
					    title: newValue
					});
				},
				immediate: true
			}
		},
		computed:{
			dataHtml(){
				//return this.dataDetail;
				return !this.dataDetail ? '' : this.dataDetail.replace(/<br\/>/ig, '')
			}
		},
		data() {
			return {
				type: 'userinfo', //协议类型
				pageTitle: '用户协议', //页面标题
				tagStyle: {
					img: 'width:100%;display:block;'
				},
				dataDetail:'',
			};
		},
		onLoad(op) {
			let that = this, query = that.$Route.query;
			if(query.type){
				that.type = query.type.trim()
			}
			//页面标题
			if(query.title){
				that.pageTitle = decodeURIComponent(query.title)
			}
			//获取协议内容
			that.loadAgreementDetail();
		},
		onUnload() {

		},
		methods: {
			//获取协议内容
			loadAgreementDetail(){
				let that = this
				getAgreementDetailApi(that.type).then(res => {
					let resData = JSON.parse(res)
					that.dataDetail = resData.agreement
					if(resData.title) that.pageTitle
				}).catch(e => {
					that.$util.Tips({
						title: e || '网络错误，请重试'
					})
				})
			}
		}
	}
</script>
<style lang="scss" scoped>
.agreementWarp{
	.text {
		font-size: 30rpx;
		font-weight: 400;
		padding: 30rpx;
		color: #282828;
	}
	.cancelTxt {
		overflow: hidden;
		overflow-y: auto;
		image{
			max-width: 100%;
		}
	}
}
</style>